package torpedo_client.guicomponents;

import java.awt.GridLayout;
import java.util.LinkedList;
import javax.swing.BorderFactory;
import javax.swing.JPanel;

public class BattleZone extends JPanel {

    private boolean ACTIVE = true;
    private LinkedList listOfSquares;
    private int squaresNumber;

    public BattleZone(boolean active, int squaresNumber, String title) {
        this.squaresNumber = squaresNumber;
        this.ACTIVE = active;
        this.makeTheSquares();
        this.addSquarestoZone();
        setBorder(BorderFactory.createTitledBorder(title));
    }

    private void makeTheSquares() {
        listOfSquares = new LinkedList<BattleSquare>();
        for (int i = 0; i < (this.squaresNumber * this.squaresNumber); i++) {
            listOfSquares.add(new BattleSquare(ACTIVE));
        }
    }

    private void addSquarestoZone() {
        this.setLayout(new GridLayout(this.squaresNumber, this.squaresNumber));
        for (int i = 0; i < (this.squaresNumber * this.squaresNumber); i++) {
            this.add((BattleSquare) this.listOfSquares.get(i));
        }

    }
}